﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;

namespace JQuery.Study.WebFormSite
{
    public class Pessoa
    {
        public string Nome { set; get; }
        public string Sobrenome { set; get; }
        public string Fone { set; get; }
        public string Email { set; get; }
    }

    // Referencias: http://www.asp.net/ajaxlibrary/jquery_webforms_Post_Data_To_PageMethod.ashx
    // Referencias: http://www.asp.net/ajaxlibrary/jquery_webforms_Retrieve_Data_From_PageMethod.ashx
    // Referencias: http://www.asp.net/ajaxlibrary/jquery_webforms_serialize_dates_to_json.ashx
    // Referencias: http://www.asp.net/ajaxlibrary/jquery_dibs.ashx
    public class NameValue
    {
        public string name { get; set; }
        public string value { get; set; }
    }

    //public static class NameValueExtensionMethods
    //{
    //    public static string Form(this  NameValue[] formVars, string name)
    //    {
    //        var matches = formVars.FirstOrDefault(nv => nv.name.ToLower() == name.ToLower());
    //        return matches != null ? matches.value : string.Empty;
    //    }

    //    public static string[] FormMultiple(this  NameValue[] formVars, string name)
    //    {
    //        var matches = formVars.Where(nv => nv.name.ToLower() == name.ToLower()).Select(nv => nv.value).ToArray();
    //        return matches.Length == 0 ? null : matches;
    //    }
    //}  

    public partial class WebMethodPost : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        [WebMethod]
        //[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)] 
        public static string ProcessAjaxFirst(Pessoa form)
        {
 //           return "chamou: " + form.Form("Nome") + " / " + form.Form("Sobrenome") + " / " + form.Form("Email") + " / " + form.Form("Fone");

            return "opa";
        }
    }
}